package com.zygh.lz.controller;

import com.zygh.lz.entity.Role;
import com.zygh.lz.entity.Staff;
import com.zygh.lz.entity.Xarea;
import com.zygh.lz.entity.remould.Matching;
import com.zygh.lz.service.StaffService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.stapprove.ViLog;
import com.zygh.lz.vo.ResultBean;
import com.zygh.lz.vo.RoleUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Api(tags = "人员类", description = "StaffController")
@RestController
public class StaffController {

    @Resource
    private StaffService staffService;

    @ApiOperation("查询默认大队")
    @GetMapping("selectStaffBySectionName")
    public ResultBean selectStaffBySectionName(Integer staffid) {
        return staffService.selectStaffBySectionName(staffid);
    }


    @ApiOperation("查询在岗人数")
    @GetMapping("selectStaffByzg")
    public ResultBean selectStaffByzg(Integer sectionId, Integer sectionPid, String sectionName) {
        return staffService.selectStaffByzg(sectionId, sectionPid, sectionName);
    }

    @GetMapping("selectStaffByName")
    //@ViLog(logType = "1", module = "根据名字模糊查询")
    public ResultBean selectStaffByName(String name, String staffHierarchy) {
        return staffService.selectStaffByName(name, staffHierarchy);
    }

    //分层级查询在岗人数
    @GetMapping("selectStaffInfoByid")
    //@ViLog(logType = "1", module = "分层级查询在岗人数")
    public ResultBean selectStaffInfoByid(Integer id) {
        return staffService.selectStaffInfoByid(id);
    }

    //应到民警
    @GetMapping("selectStaffYdByAll")
    public ResultBean selectStaffYdByAll(Integer SectionId) {
        return staffService.selectStaffYdByAll(null, SectionId);
    }

    //在线民警
    @GetMapping("selectpoliceZx")
    public ResultBean selectpoliceZx(String station) throws Exception {
        return staffService.selectpoliceZx(station);
    }

    //查询该人的直系领导
    @GetMapping("selectStaffByid")
    public ResultBean selectStaffByid(Integer id) {
        return staffService.selectStaffByid(id);
    }


    @GetMapping("selectXareaByid")
    @ViLog(logType = "1", module = "根据民警id查询该民警所负责的路段")
    public ResultBean selectXareaByid(Integer id) throws Exception {
        return staffService.selectXareaByid(id);
    }


    @ApiOperation("查询昨日总警力")
    @ApiImplicitParam(name = "battalion", value = "大队名称", dataType = "String")
    @GetMapping("selecttotalforces")
    public ResultBean selecttotalforces(String battalion) {
        return staffService.selecttotalforces(battalion);
    }

    @ApiOperation("昨日在线警力之和按大队查询昨日总警力")
    @ApiImplicitParam(name = "battalion", value = "大队名称", dataType = "String")
    @GetMapping("selecttotalforceszr")
    public ResultBean selecttotalforceszr(String battalion) {
        return staffService.selecttotalforceszr(battalion);
    }


    @ApiOperation("在线右侧信息栏人员详情")
    @GetMapping("selectzaBystation")
    public ResultBean selectzaBystation(String station, String conment, String grid, String battalion) {
        return staffService.selectzaBystation(station, conment, grid, battalion);
    }


    @ApiOperation("查询其他在岗人")
    @GetMapping("selectStaffByqita")
    public ResultBean selectStaffByqita() {
        return staffService.selectStaffByqita();
    }

    @ApiOperation("以单位为结构显示信息列表")
    @GetMapping("selectAllbytype")
    public ResultBean selectAllbytype(String battalion) {
        return staffService.selectAllbytype(battalion);
    }


    @ApiOperation("在线右侧信息栏")
    @GetMapping("selectcountBysection")
    public ResultBean selectcountBysection(Xarea xarea) {
        return staffService.selectcountBysection(xarea);
    }

    @ApiOperation("根据岗位查询各大队下各中队在线民警")
    @GetMapping("selectcountBydetachment")
    public ResultBean selectcountBydetachment(Xarea xarea) {
        return staffService.selectcountBydetachment(xarea);
    }


    @ApiOperation("特殊勤务当班在线警力")
    @GetMapping("specialOn")
    public ResultBean specialOn() {
        return staffService.specialOn();
    }

    @ApiOperation("首页右侧信息栏个人详情")
    @GetMapping("findStaffByid")
    public ResultBean findStaffByid(Integer id) {
        return staffService.findStaffByid(id);
    }


    @ApiOperation("首页右侧根据警号或姓名查询警员信息")
    @GetMapping("findStaffByWarningSignal")
    public ResultBean findStaffByWarningSignal(Integer sectionId, String warningSignal) {
        return staffService.findStaffByWarningSignal(sectionId, warningSignal);
    }


    @ApiOperation("人员信息新增")
    //@PostMapping("/addStaff")
    //@SysPcLog(module = "人员信息新增",operation = "新增")
    public ResultBean addStaff(@RequestBody Staff staff) {
        return staffService.addStaff(staff);
    }

    @ApiOperation("修改人员信息")
    //@PostMapping("/updateStaff")
    public ResultBean updateStaff(@RequestBody Staff staff) {
        return staffService.updateStaff(staff);
    }

    /**
     * ================================新增==========================================
     */
    @ApiOperation("根据大队和岗位查询在线人员信息")
    @GetMapping("OnlineDetails")
    public ResultBean OnlineDetails(String station, String battalion) {
        return staffService.OnlineDetails(station, battalion);
    }

    @ApiOperation("APP人员信息>修改")
    @PostMapping("modifus")
    @ViLog(logType = "3", module = "人员信息>修改")
    public ResultBean modifus(@RequestBody Staff staff) {
        return staffService.updaStaffInfo(staff);
    }


    @ApiOperation("根据姓名、大队、中队、警号查询人员")
    @GetMapping("findStaffInfoByAll")
    public ResultBean findStaffInfoByAll(String staffName, String warningsignal, Integer sectionid, String staffType) {
        return ResultUtil.setOK("success", staffService.findStaffInfoByAll(staffName, warningsignal, sectionid, staffType));
    }

    @ApiOperation("根据姓名、大队、中队、警号查询人员分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer", required = true)

    })
    @GetMapping("findStaffInfoByPage")
    public ResultBean findStaffInfoByPage(String staffName, String warningsignal, Integer sectionid, String staffType,
                                          @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return ResultUtil.setOK("success", staffService.findStaffInfoByPage(staffName, warningsignal, sectionid, staffType, pageNum, pageSize));
    }

    @ApiOperation("根据id查询人员信息")
    @GetMapping("selectStaffInfoById")
    public ResultBean selectStaffInfoById(Integer id) {
        Map staff = staffService.selectStaffInfoById(id);
        return ResultUtil.setOK("success", staff);
    }

    @ApiOperation("根据警号查询人员信息")
    @GetMapping("selectStaffByNum")
    public ResultBean selectStaffByNum(String staffNum) {
        Staff staff = staffService.selectStaffByNum(staffNum);
        return ResultUtil.setOK("success", staff);
    }

    @ApiOperation("根据大队、中队、在线/不在线、民警辅警、岗位")
    @GetMapping("selectStaffMatching")
    public ResultBean selectStaffMatching(Matching matching) {
        return staffService.selectStaffMatching(matching);
    }


    @ApiOperation("根据大队、中队、在线/不在线、民警辅警")
    @GetMapping("selectStaffOnLine")
    public ResultBean selectStaffOnLine(Matching matching,
                                        @RequestParam(name = "current", defaultValue = "1") Integer current,
                                        @RequestParam(name = "size", defaultValue = "10") Integer size) {
        return staffService.selectStaffOnLine(matching, current, size);
    }


    @ApiOperation("根据大队、中队、在线/不在线、民警辅警")
    @GetMapping("exportStaffOnLine")
    public String exportStaffOnLine(HttpServletResponse response, Matching matching) throws IOException {
        return staffService.exportStaffOnLine(response, matching);
    }


    @ApiOperation("查询所有指挥中心信息")
    @GetMapping("selectCommandCenter")
    public ResultBean selectCommandCenter() {
        return staffService.selectCommandCenter();
    }


    @ApiOperation("删除人员信息")
    @PostMapping("/delete")
    @SysPcLog(module = "删除人员信息",operation = "删除")
    public ResultBean delete(Integer id){
       return staffService.delStaffInfoById(id);
    }

    @ApiOperation("根据角色查询用户")
    @GetMapping("/role/user")
    public ResultBean roleUser(RoleUserVo role){
        return staffService.roleUser(role);
    }
}
